<!--节能节水项目 savingProject-->
<template>
    <Layout>
        <Form ref="queryForm" :model="dataToQuery" :label-width="120">
            <Row v-show="!switchFlag" class="query-form" >
                <Col span="8">
                    <FormItem label="企业名称：" prop="order">
                        <cascader-dom class="query-form-el" ref='queryOrgCascader' :orgTree="true" @setOrgInfo='setQueryCompanyId'
                              :currentOrgId="dataToQuery.companyId" :setCurrentName="{label:dataToQuery.companyName,value:dataToQuery.companyId}"></cascader-dom>
                    </FormItem>
                </Col>
                <Col span="8">
                    <FormItem label="填报时间：" prop="content" >
                        <DatePicker class="query-form-el" v-model="dataToQuery.dateRange" format="yyyy-MM-dd" type="daterange" placement="bottom-end" placeholder="请选择查询时间段"
                                    @on-change="onSelectQueryDateRange"></DatePicker>
                    </FormItem>
                </Col>
                <Col span="8">
                    <Button @click="switchQuery(true)" class="ivu-btn-switch" type="text">展开∨</Button>
                    <Button @click="reset1" class="ivu-btn-reset"  >重置</Button>
                    <Button type="primary" class="ivu-btn-query"   icon="md-search"  @click="query">查询</Button>
                </Col>
            </Row>
            <Row v-show="switchFlag" class="query-form">
                <Col span="8">
                    <FormItem label="企业名称：" prop="belongOrgId">
                        <cascader-dom class="query-form-el" ref='queryOrgCascader1' :orgTree="true" @setOrgInfo='setQueryCompanyId'
                                      :currentOrgId="dataToQuery.companyId" :setCurrentName="{label:dataToQuery.companyName,value:dataToQuery.companyId}"></cascader-dom>
                    </FormItem>
                </Col>
                <Col span="8">
                    <FormItem label="填报时间：" prop="content" >
                        <DatePicker class="query-form-el" v-model="dataToQuery.dateRange" format="yyyy-MM-dd" type="daterange" placement="bottom-end" placeholder="请选择查询时间段"
                                    @on-change="onSelectQueryDateRange"></DatePicker>
                    </FormItem>
                </Col>
                <Col span="8">
                    <FormItem label='项目类型：' prop='projectType'>
                        <Input class="query-form-el" type='text' v-model='dataToQuery.projectType'></Input>
                    </FormItem>
                </Col>
            </Row>
            <Row v-show="switchFlag" class="query-form">
                <Col span="8">
                    <FormItem label='节约资金：' prop='savingAmount'>
                        <InputNumber type='text' v-model='dataToQuery.savingAmountFrom' style="width: 46%" :min="0"></InputNumber> -
                        <InputNumber type='text' v-model='dataToQuery.savingAmountTo' style="width: 46%" :min="0"></InputNumber>
                    </FormItem>
                </Col>
                <Col span="8" offset="8">
                    <Button @click="switchQuery(false)" class="ivu-btn-switch" type="text">收起∧</Button>
                    <Button @click="reset1" class="ivu-btn-reset">重置</Button>
                    <Button class="ivu-btn-query" icon="md-search" @click="query">查询</Button>
                </Col>
            </Row>
            <Row class="query-form">
                <Col span="24">
                    <Button size="large"  class="ivu-btn-add" icon="md-add"  @click="addInfo">新增</Button>
                </Col>
            </Row>
        </Form>
        <Table ref='table' :height="tableHeight"  no-data-text="没有查询到相关数据!" @on-selection-change = 'getSelectRows' :loading='pageStatus.loading'
               border :columns="columns1"  :data="dataTable" >
        </Table>
        <Row style="margin-right:10px;">
            <Col span="24" >
                <Page style="float: right" :total="pagedata.total" :page-size="pagedata.pageSize" @on-change="pageChange" @on-page-size-change="pageSizeChange" :page-size-opts="pageSizeArray" show-total show-sizer show-elevator />
            </Col>
        </Row>
        <Modal  title="节能节水项目登记" :transfer=false :mask-closable="false" v-model="dialogShow" v-if="dataToView && dialogShow" :width=800 :styles="{height:'726px'}"  class-name='limit-height-dialog'>
            <Row>
                <Col span="24">
                    <Form ref="dialogForm" :class="mode === 'view'?'modal-view-detail':'modal-form'" :show-message="false" :model="dataToView" :rules="mode === 'view'?{} :ruleCustom"  :label-position="mode === 'view'?'right':'top'" :label-width="mode === 'view'?180:null">
                        <Row type="flex" justify="space-around" class="code-row-bg">
                            <Col span="23">
                                <FormItem label='企业名称：' prop='companyId'>
                                    <div v-if="mode === 'view'">{{dataToView.companyName}}</div>
                                    <cascader-dom v-else ref='orgCascader' @setOrgInfo='setCompanyId' @setOrgname="setCompanyName" :orgTree="true" :currentOrgId = "dataToView.companyId" :setCurrentName="{label:dataToView.companyName,value:dataToView.companyId}" ></cascader-dom>
                                </FormItem>
                            </Col>
                        </Row>
                        <Row type="flex" justify="space-around" class="code-row-bg">
                            <Col span="11">
                                <FormItem label='年度：' prop='energyYearDate'>
                                    <div v-if="mode === 'view'">{{dataToView.energyYear}}</div>
                                    <DatePicker v-else type="year" placeholder="请选择年度" v-model='dataToView.energyYearDate' class="query-form-el"></DatePicker>
                                </FormItem>
                            </Col>
                            <Col span="11">
                                <FormItem label='项目类型：' prop='city'>
                                    <div v-if="mode === 'view'">{{dataToView.projectType}}</div>
                                    <Input v-else v-model='dataToView.projectType' class="query-form-el"></Input>
                                </FormItem>
                            </Col>
                        </Row>
                        <Row type="flex" justify="space-around" class="code-row-bg">
                            <Col span="11">
                                <FormItem label='数量：' prop='projectNumber'>
                                    <div v-if="mode === 'view'">{{dataToView.projectNumber}}</div>
                                    <InputNumber v-else class="query-form-el" v-model='dataToView.projectNumber' :min="0"></InputNumber>
                                </FormItem>
                            </Col>
                            <Col span="11">
                                <FormItem label='投资金额（万元）：' prop='investAmount'>
                                    <div v-if="mode === 'view'">{{dataToView.investAmount}}</div>
                                    <InputNumber v-else class="query-form-el" v-model='dataToView.investAmount' :min="0"></InputNumber>
                                </FormItem>
                            </Col>
                        </Row>
                        <Row type="flex" justify="space-around" class="code-row-bg">
                            <Col span="23">
                                <FormItem label='项目基本内容：' prop='projectDesc'>
                                    <div v-if="mode === 'view'">{{dataToView.projectDesc}}</div>
                                    <Input v-else type='textarea' v-model='dataToView.projectDesc' class="query-form-el"></Input>
                                </FormItem>
                            </Col>
                        </Row>
                        <Row type="flex" justify="space-around" class="code-row-bg">
                            <Col span="11">
                                <FormItem label='节能量（吨标准煤/年）：' prop='savingEnergy'>
                                    <div v-if="mode === 'view'">{{dataToView.savingEnergy}}</div>
                                    <InputNumber v-else class="query-form-el" v-model='dataToView.savingEnergy' :min="0"></InputNumber>
                                </FormItem>
                            </Col>
                            <Col span="11">
                                <FormItem label='节约资金（万元）：' prop='savingAmount'>
                                    <div v-if="mode === 'view'">{{dataToView.savingAmount}}</div>
                                    <InputNumber v-else class="query-form-el" v-model='dataToView.savingAmount' :min="0"></InputNumber>
                                </FormItem>
                            </Col>
                        </Row>
                        <Row type="flex" justify="space-around" class="code-row-bg">
                            <Col span="11">
                                <FormItem label='完成时间：' prop='wellPlan'>
                                    <div v-if="mode === 'view'">{{renderViewDate(dataToView.finishTime)}}</div>
                                    <DatePicker v-else type="date" placeholder="请选择日期" class="query-form-el" v-model='dataToView.finishTime'></DatePicker>
                                </FormItem>
                            </Col>
                            <Col span="11">
                                <FormItem label='填报人：' prop='registrant'>
                                    <div v-if="mode === 'view'">{{dataToView.registrant}}</div>
                                    <Input v-else v-model='dataToView.registrant' class="query-form-el" readonly></Input>
                                </FormItem>
                            </Col>
                        </Row>
                        <Row type="flex" justify="space-around" class="code-row-bg">
                            <Col span="11">
                                <FormItem label='填报时间：' prop='wellPlan'>
                                    <div v-if="mode === 'view'">{{renderViewDate(dataToView.createDate)}}</div>
                                    <DatePicker v-else type="date" placeholder="请选择日期" class="query-form-el" v-model='dataToView.createDate' readonly></DatePicker>
                                </FormItem>
                            </Col>
                            <Col span="11">
                                <FormItem label='联系电话：' prop='telephone'>
                                    <div v-if="mode === 'view'">{{dataToView.telephone}}</div>
                                    <Input v-else v-model='dataToView.telephone' class="query-form-el"></Input>
                                </FormItem>
                            </Col>
                        </Row>
                        <Row type="flex" justify="space-around" class="code-row-bg">
                            <Col span="11">
                                <FormItem label='邮箱：' prop='email'>
                                    <div v-if="mode === 'view'">{{dataToView.email}}</div>
                                    <Input v-else v-model='dataToView.email' class="query-form-el"></Input>
                                </FormItem>
                            </Col>
                            <Col span="11">
                            </Col>
                        </Row>
                        <Row type="flex" justify="space-around" class="code-row-bg">
                            <Col span="23">
                                <FormItem label='备注：' prop='notes'>
                                    <div v-if="mode === 'view'">{{dataToView.notes}}</div>
                                    <Input v-else type='textarea' v-model='dataToView.notes'></Input>
                                </FormItem>
                            </Col>
                        </Row>
                    </Form>
                </Col>
            </Row>
            <div slot="footer">
                <Button v-if="mode != 'view'" type="primary"  class='ivu-btn-save' @click="submit('dialogForm')" >确定</Button>
                <Button v-if="mode != 'view'" type="primary"  class='ivu-btn-cancel' @click="handleCancel" >取消</Button>
                <Button v-if="mode === 'view'" class='ivu-btn-save' @click="dialogShow=false">关闭</Button>
            </div>
        </Modal>
    </Layout>
</template>

<script>
    import {Api} from '@/api/index.js'
    import {formatDate, verifyMobileTel } from '@/tools/index'
    import _deepclone from 'lodash/cloneDeep'
    var cascaderDom = () => import('@/components/cascader-dom.vue');
    import pageCommonFunction from '@/components/pageCommonFunction.js'
    export default {
        components:{
            cascaderDom
        },
        data(){
            return {
                ...this.createCommonDataField(),
                columns1: [
                    { title: '序号', width: 80, fixed: 'left', align: 'center', render: this.indexColumnsRender},
                    { key:'companyName',title: '企业名称',  align: 'center', minWidth: 200},
                    { key:'energyYear',title: '年度',  align: 'center', width: 100, render: (h, params) => {return h('span', formatDate(new Date(params.row.energyYear), "yyyy"))}},
                    { key:'projectType',title: '项目类型',  align: 'center', width: 120},
                    { key:'projectNumber',title: '项目数量',  align: 'center', width: 120 },
                    { key:'projectDesc',title: '项目基本内容',  align: 'center', width: 130 },
                    { key:'investAmount',title: '投资金额（万元）',  align: 'center', width: 140 },
                    { key:'savingEnergy',title: '节能量（吨标准煤/年）',  align: 'center', width: 170 },
                    { key:'savingAmount',title: '节约资金（万元）',  align: 'center' , width: 150 },
                    { key:'finishTime',title: '完成时间',  align: 'center', width: 120, render: this.renderCellDate },
                    { key:'registrant',title: '填报人',  align: 'center', width: 120  },
                    { key:'createDate',title: '填报时间',  align: 'center', width: 120, render: this.renderCellDate  },
                    { key:'telephone',title: '联系电话',  align: 'center', width: 120 },
                    { key:'email',title: '邮箱',  align: 'center', width: 120 },
                    { key:'notes',title: '备注',  align: 'center', width: 120 },
                    this.getActionColumns()
                ],
                ruleCustom : {
                    companyId: [{ required: true, message: '请填写企业名称', trigger: 'change' }],
                    energyYearDate: [{ required: true, message: '请填写年度', trigger: 'change', type:'date' }],
                    // projectNumber: [
                    //     { pattern: /^(0|[1-9][0-9]*)(\.\d+){0,1}$/, message: '项目数量必须为数字', trigger: 'change',type:'number'}
                    // ],
                    // investAmount: [
                    //     { pattern: /^([0-9][0-9]*)+(.[0-9]{1,4})?$/, message: '投资金额（万元）必须为数字', trigger: 'change',type:'number'}
                    // ],
                    // savingEnergy: [
                    //     { pattern: /^([0-9][0-9]*)+(.[0-9]{1,4})?$/, message: '节能量（吨标准煤/年）必须为数字', trigger: 'change',type:'number'}
                    // ],
                    // savingAmount: [
                    //     { pattern: /^([0-9][0-9]*)+(.[0-9]{1,4})?$/, message: '节约资金（万元）必须为数字', trigger: 'change', type:'number'}
                    // ],
                    telephone: [
                        { validator: verifyMobileTel,  trigger: 'change'}
                    ],
                    email: [
                        { pattern: /^[A-Za-z\d]+([-_.][A-Za-z\d]+)*@([A-Za-z\d]+[-.])+[A-Za-z\d]{2,4}$/, message: '请输入正确的邮件格式', trigger: 'change'}
                    ],
                },
                tableHeight:10,
                // api
                queryUrl:Api.queryEnergySavingProject,
                deleteUrl:Api.deleteEnergySavingProject,
                bthDeleteUrl:Api.batchDeleteEnergySavingProject,
                getUrl:Api.getEnergySavingProject,
                updateUrl:Api.updateEnergySavingProject,
                saveUrl:Api.saveEnergySavingProject,
            }
        },
        mounted() {
             this.setTableHeight();
            this.reset1();
        },
        methods:{
            ...pageCommonFunction,
            deleteData(params) {
                this.deleteDateAjax(params);
            },
            setEnergyYear(value, date) {
                console.log(value)
                this.dataToView.energyYear = value;
            },
            reset1(){
                this.reset()
                this.dataToQuery.savingAmountFrom = null;
                this.dataToQuery.savingAmountTo = null;
            },
            query() {
                this.queryAjax();
            },
            submit(name) {
                if(this.dataToView.energyYearDate) {
                    this.dataToView.energyYear = this.dataToView.energyYearDate.getFullYear();
                }
                this.submitAjax(name);
            },
            createEmptyDataToAdd() {
                return {
                    projectNumber:'',
                    investAmount:'',
                    savingEnergy:'',
                    savingAmount:'',
                    registrant: this.currentUser.userName,
                    createDate: new Date()
                }
            }
        },
        watch:{
        },

    }
</script>

<style lang='css' scoped>

</style>
